package cn.melon.view.control;

import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URI;

/**
 * @ClassName: OpenBrowser
 * @author Hzy
 * 监听器，在单击时打开url指定的网站
 */
public class OpenBrowser implements ActionListener{
    private String url;
    public OpenBrowser(String url){
        this.url = url;
    }
    @Override
    public void actionPerformed(ActionEvent event){
        try{
            Desktop desktop = Desktop.getDesktop();
            if(desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)){
                URI uri = new URI(url);
                desktop.browse(uri);
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
